#modprobe tkusb  
#modprobe hal_x86
#modprobe pehci
#sleep 1

#start eth0
ifconfig lo up
ifconfig lo:0 192.168.1.1 netmask 255.255.255.0
(ifconfig eth0 down; udhcpc -i eth0 -b -T 3 -t 3) &

export LD_LIBRARY_PATH=/opt/qt-embedded/lib:/space/cp/arm/dbus/lib
mkdir -p /USER
mount -o noatime /dev/mmcblk0p2 /USER

if [ -f /root/.sync ]; then                                                                                              
  echo "Starting Update please wait ..."  

  #display update image
  cd /home/radalt/bin   
  ./fbi -d /dev/fb0 -1 -t 1 radalt_rpmupdate.bmp
                                                                                  
  umount /var

  #update application
  cd /USER/rpm
  rpm -Uvh --force *.rpm
     
  rm -rf /root/.sync
  rm -Rf /USER/space/cp/*
  mount -a 
  
  echo "Update Done..."
fi

#force removal of system.xml
if [ -f /space/cp/target/ARM/rci/xml/system.xml ]; then
  rm /space/cp/target/ARM/rci/xml/system.xml
fi

depmod
modprobe omap-pci
modprobe omap_bl
modprobe omap_jtag
#modprobe g_ether
swapon /dev/mmcblk0p1
#sync

#moved this for the new touchscreen controller since
#there are changes to the evars file
source /etc/evars

#start the touch screen driver
/usr/bin/eGTouchD &

#sleep 2
#mount -o noatime /dev/mmcblk0p1 /tmp/ltib/
mkdir -p /opt
cd /opt; ln -sf /space/cp/arm/qt-embedded qt-embedded
cd /opt; ln -sf /space/cp/target/ARM/engines/ engines
cd /opt; ln -sf /space/cp/target/ARM/UI/ UI

#Read home button
homebutton=`/home/radalt/bin/i2c_read 3 0x62 0x04 1`
hexhomebutton="0x"${homebutton}
#Check if homebutton is depressed
dotouchcal=$(( $hexhomebutton & 0x20 ? 1 : 0 ))
if [ $dotouchcal == 1 ]; then
  echo "Write out .touchcal"
  touch /space/cp/.touchcal
fi

if [ -f /space/cp/.touchcal ]; then  
  sleep 15
  echo "Starting touchscreen cal Please Wait ..."
  rm -rf /etc/pointercal-2
  ts_calibrate
  rm -rf /space/cp/.touchcal
  cat /etc/pointercal-2
fi
#Handhelds Slot-1 controller - Backplane TCXO & Pullups
#Check to see if the i2c DS4520 part has been programmed yet.
#If not, program it.
mytemp=`/home/radalt/bin/i2c_read 3 0x51 0xf0 4`
I2CBYTES=${mytemp//[[:space:]]}
if [ $I2CBYTES != "0000E001" ]; then
   echo "Programming DS4520 TCXO/Pullups..."
   /home/radalt/bin/i2c_write 3 0x51 0xf4 0x0
   /home/radalt/bin/i2c_write 3 0x51 0xf0 0 0 0xe0 0x01
   /home/radalt/bin/i2c_write 3 0x51 0xf4 0x01
fi

#these must be killed before changing the file system to Read-Only
killall syslogd
/home/radalt/bin/checklog &
export LD_LIBRARY_PATH=/space/cp/arm/ACE_wrappers/lib:/space/cp/target/ARM/UI/:/space/cp/arm/qt-embedded/lib:/space/cp/arm/expat/lib:/space/cp/arm/dbus/lib:/space/cp/arm/DDS/lib:/space/cp/arm/sqlite/lib:/space/cp/arm/zlib/lib:/space/cp/target/ARM/engines/lib
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/space/cp/arm/ACE_wrappers/bin:/space/cp/arm/DDS/bin:/space/cp/arm/ACE_wrappers/TAO/orbsvcs/Naming_Service/:/space/cp/target/ARM/engines/lib:/space/cp/target/ARM/UI/:/space/cp/target/ARM/UI/plugins:/space/cp/arm/dbus/bin:/space/cp/arm/expat/bin:/space/cp/arm/sqlite/bin
export QT_PLUGIN_PATH=/space/cp/target/ARM/UI/plugins
cd /space/cp/target/ARM/engines/lib
echo 70bf6735fe623d0835da9c4b3a50791c > /space/cp/arm/dbus/var/lib/dbus/machine-id
ulimit -s 1024
tao_cosnaming -ORBListenEndpoints iiop://192.168.1.1:2700 &
sleep 3
rm -rf /space/cp/target/ARM/engines/lib/repo.ior
DCPSInfoRepo -ORBListenEndpoints iiop://192.168.1.1:12345  -d /space/cp/target/ARM/engines/lib/domain_ids -ORBSvcConf /space/cp/target/ARM/engines/lib/tcp.conf -DCPSConfigFile /space/cp/target/ARM/engines/lib/dds.ini &
timeout=15
while true
do 
  if [ -f /space/cp/target/ARM/engines/lib/repo.ior ]
  then
    break
  else
    echo "waiting for repo.ior"
    sleep 1 
    let "timeout-=1"
    if [ $timeout -lt 0 ]
    then
      echo "TIMEOUT - could not find repo.ior"
      break    
    fi      
  fi
done
sleep 2
#copy log file to usb stick
usb_mount=`mount | grep /dev/sda1 | cut -d' ' -f3`
if [ "$usb_mount" = "/media/usb_aeroflex" ]; then
  mount -o remount,rw /media/usb_aeroflex
  cp /USER/log/.lastrs232.txt /media/usb_aeroflex/alt8000last_rs232.txt  
  cp /dev/shm/.rs232output.txt /media/usb_aeroflex/alt8000rs232.txt
  mount -o remount,ro /media/usb_aeroflex     
fi
mkdir -p /media
mount -o remount,ro /
./hardware_enumeration.engine -ORBInitRef NameService=corbaloc:iiop:192.168.1.1:2700/NameService -ORBSvcConf /space/cp/target/ARM/engines/lib/tcp.conf -DCPSConfigFile /space/cp/target/ARM/engines/lib/dds.ini &
  